#include <math.h>

#include "../include/vector.h"

Vector::Vector() {
	x = 0.0;
	y = 0.0;
	z = 0.0;
}

void Vector::set(double px, double py, double pz) {
	x = px;
	y = py;
	z = pz;
}

void Vector::normalise(void) {
	double l;

	l = x * x + y * y + z * z;
	l = sqrt(l);

	x = x / l;
	y = y / l;
	z = z / l;
}

double Vector::dot(const Vector &b) {
	return (x * b.x) + (y * b.y) + (z * b.z);
}

//double Vector::dot(const Vertex  &b) {
//	return (x * b.x) + (y * b.y) + (z * b.z);
//}

Vector Vector::cross(const Vector &b) {
	Vector result;
	Vector a = *this;
	result.set(a.y * b.z - a.z * b.y , a.z * b.x - a.x * b.z , a.x * b.y - a.y * b.x);
	return result;
}

Vector Vector::multiply(const Vector &b) {
	Vector result;
	Vector a = *this;
	result.set(a.x * b.x , a.y * b.y , a.z * b.z);
	return result;
}

Vector Vector::subtract(const Vector &b) {
	Vector result;
	Vector a = *this;
	result.set(a.x - b.x , a.y - b.y , a.z - b.z);
	return result;
}

Vector Vector::add(const Vector &b) {
	Vector result;
	Vector a = *this;
	result.set(a.x + b.x , a.y + b.y , a.z + b.z);
	return result;
}








Vector Vector::multiply(double d) {
	Vector result;
	Vector a = *this;
	result.set(a.x * d , a.y * d , a.z * d);
	return result;
}

Vector Vector::subtract(double d) {
	Vector result;
	Vector a = *this;
	result.set(a.x - d , a.y - d , a.z - d);
	return result;
}

Vector Vector::add(double d) {
	Vector result;
	Vector a = *this;
	result.set(a.x + d , a.y + d , a.z + d);
	return result;
}



void Vector::multiply (const Matrix& mat) {
	double newx,newy,newz;
	newx = mat.m[0][0] * x + mat.m[0][1] * y + mat.m[0][2] * z;
	newy = mat.m[1][0] * x + mat.m[1][1] * y + mat.m[1][2] * z;
	newz = mat.m[2][0] * x + mat.m[2][1] * y + mat.m[2][2] * z;
	x=newx;y=newy;z=newz;
}



Vector& Vector::operator/ (double doub){
	Vector vector;
	vector.set(x / doub, y / doub, z / doub);
	return vector;

}








